﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace UTSuperCalc
{
    [TestClass]
    public class CalculateTest
    {
        #region 测试加法运算的结果
        /// <summary>
        /// 测试加法运算的结果
        /// </summary>
        [TestMethod]
        public void TestAddition_result()
        {
            //初始化相关变量
            SuperCalc.Calculate cl = new SuperCalc.Calculate();
            string msg = "";//函数信息
            decimal expected = 0;//预期
            decimal actual = 0;//实际
            //正常结果
            //第1次测试
            expected = 50;
            msg = "";
            Assert.AreEqual(expected, cl.Addition("23", "27", out msg));
            Assert.AreEqual("", msg);
            //第2次测试
            msg = "";
            expected = -1;
            Assert.AreEqual(expected, cl.Addition("-1", "0", out msg));
            Assert.AreEqual("", msg);
            //第3次测试，小数测试
            expected = 56.78M;
            msg = "";
            Assert.AreEqual(expected, cl.Addition("56", "0.78", out msg));
            Assert.AreEqual("", msg);
            //错误但能捕获到的结果
            //第4次测试，加数格式不对
            msg = "";
            expected = 0;
            actual = cl.Addition("ack", "145", out msg);
            Assert.AreEqual(expected, actual);
            Assert.AreEqual("加数字符串转换失败。", msg);
            //第5次测试被加数格式不对
            msg = "";
            expected = 0;
            actual = cl.Addition("125", "adkc", out msg);
            Assert.AreEqual(expected, actual);
            Assert.AreEqual("被加数字符串转换失败。", msg);
        }

        #endregion

        #region 减法运算结果测试
        /// <summary>
        /// 减法运算结果测试
        /// </summary>
        [TestMethod]
        public void TestSubtraction_result()
        {
            //初始化基本的变量
            decimal expected = 0;//预期
            decimal actual = 0;//实际
            string msg = "";//函数中的信息
            SuperCalc.Calculate cl = new SuperCalc.Calculate();
            //计算平常的正确结果
            //第1次计算
            expected = 25;
            msg = "";
            actual = cl.Subtraction("65", "40", out msg);
            Assert.AreEqual(expected, actual);
            Assert.AreEqual("", msg);
            //第2次计算
            expected = -25;
            msg = "";
            actual = cl.Subtraction("65", "90", out msg);
            Assert.AreEqual(expected, actual);
            Assert.AreEqual("", msg);
            //todo:观察主窗体的基本运算界面上的输入框最大能接受多少位的数然后再次测试
            //第3次计算，接近最大值±1.0 × 10e−28 至 ±7.9 × 10e28，±79228162514264337593543950335
            expected = 14264337593543950334;
            msg = "";
            actual = cl.Subtraction("14264337593543950335", "1", out msg);
            Assert.AreEqual(expected, actual);
            Assert.AreEqual("", msg);
            //第4次计算，减数为负数
            expected = 25;
            msg = "";
            actual = cl.Subtraction("20", "-5", out msg);
            Assert.AreEqual(expected, actual);
            Assert.AreEqual("", msg);
            //第5次计算，小数运算
            msg = "";
            expected = 24.6M;
            actual = cl.Subtraction("30", "5.4", out msg);
            Assert.AreEqual(expected, actual);
            Assert.AreEqual("", msg);
            //可预测的错误
            //第6次计算，被减数字符串不符合规范
            expected = 0;
            msg = "";
            actual = cl.Subtraction("adgb", "5", out msg);
            Assert.AreEqual(expected, actual);
            Assert.AreEqual("被减数转换失败。", msg);
            //第7次计算，减数字符串不符合规范
            expected = 0;
            msg = "";
            actual = cl.Subtraction("5", "adgb", out msg);
            Assert.AreEqual(expected, actual);
            Assert.AreEqual("减数转换失败。", msg);
        }
        #endregion

        #region 乘法运算结果测试
        [TestMethod]
        public void Testmultiplication_result()
        {
            //初始化变量
            SuperCalc.Calculate cl = new SuperCalc.Calculate();
            decimal expected = 0;//预期
            decimal actual = 0;  //实际
            string msg = "";     //消息
            //正常值测试
            //第1次测试,双正数
            expected = 144;
            msg = "";
            actual = cl.Multiplication("12", "12", out msg);
            Assert.AreEqual(expected, actual);
            Assert.AreEqual("", msg);
            //第2次测试，一正一负
            expected = -144;
            msg = "";
            actual = cl.Multiplication("12", "-12", out msg);
            Assert.AreEqual(expected, actual);
            Assert.AreEqual("", msg);
            //第3次测试，双负
            expected = 144;
            msg = "";
            actual = cl.Multiplication("-12", "-12", out msg);
            Assert.AreEqual(expected, actual);
            Assert.AreEqual("", msg);
            //第4次测试，小数点
            expected = 1.44M;
            msg = "";
            actual = cl.Multiplication("1.2", "1.2", out msg);
            Assert.AreEqual(expected, actual);
            Assert.AreEqual("", msg);
            //可预测的错误信息
            //第5次测试，被乘数不符合规范
            expected = 0;
            msg = "";
            actual = cl.Multiplication("hgja", "90", out msg);
            Assert.AreEqual(expected, actual);
            Assert.AreEqual("被乘数转换失败。", msg);
            //第6次测试，乘数不符合规范
            expected = 0;
            msg = "";
            actual = cl.Multiplication("90", "khggh", out msg);
            Assert.AreEqual(expected, actual);
            Assert.AreEqual("乘数转换失败。", msg);
        }
        #endregion

        #region 测试除法运算
        [TestMethod]
        public void TestDivision_result()
        {
            //初始化变量
            SuperCalc.Calculate cl = new SuperCalc.Calculate();
            decimal expected = 0;//预期
            decimal actual = 0;//实际
            string msg = "";//消息
            //正常运算
            //第1次测试，正常运算
            expected = 2;
            msg = "";
            actual = cl.Division("24", "12", out msg);
            Assert.AreEqual(expected, actual);
            Assert.AreEqual("", msg);
            //第2次测试，一正一负
            expected = -24;
            msg = "";
            actual = cl.Division("-48", "2", out msg);
            Assert.AreEqual(expected, actual);
            Assert.AreEqual("", msg);
            //第3次测试，双负
            expected = 24;
            msg = "";
            actual = cl.Division("-48", "-2", out msg);
            Assert.AreEqual(expected, actual);
            Assert.AreEqual("", msg);
            //第4次测试，小数点测试
            expected = 1.2M;
            msg = "";
            actual = cl.Division("1.44", "1.2", out msg);
            Assert.AreEqual(expected, actual);
            Assert.AreEqual("", msg);
            //可预测的错误捕捉
            //第5次测试，被除数转换失败
            expected = 0;
            msg = "";
            actual = cl.Division("g", "12", out msg);
            Assert.AreEqual(expected, actual);
            Assert.AreEqual("被除数转换失败。", msg);
            //第6次测试，除数转换失败
            expected = 0;
            msg = "";
            actual = cl.Division("12","h",out msg);
            Assert.AreEqual(expected, actual);
            Assert.AreEqual("除数转换失败。", msg);
            //第7次测试，除数为0
            expected = 0;
            msg = "";
            actual = cl.Division("144", "0", out msg);
            Assert.AreEqual(expected, actual);
            Assert.AreEqual("除数不能为0。", msg);
        }
        #endregion
    }
}
